<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin_partenaires extends CI_Controller {
	
	function index()
	{
		$data['error'] ='display: none;';
		$data['partenaire']  ='active';
		if($this->session->userdata('email') || $this->session->userdata('logged'))
		{	
				$data['title'] = 'Admin Partenaires';
				$this->load->model('admin_model');	
				$data['partenaires'] = $this->home_model->list_partenaires();	
				$data['message'] = $this->admin_model->list_message();
				$data['content'] = 'admin/admin_partenaires';
				$this->load->view('admin/template/template',$data);
		}
		else 
		{
			$this->load->view('admin/signup',$data);
		}
	}

	function delete_partenaires()
	{
		if($this->session->userdata('email') || $this->session->userdata('logged'))
		{
			if($this->uri->segment(3))
			{
				
			$this->load->model('admin_model');
			$data['row'] = $this->admin_model->get_partenaires($this->uri->segment(3));
			$IMAGE = $data['row']->partenaires_photos;
			
			@unlink('uploads/partenaires/'.$IMAGE);
			@unlink('uploads/partenaires/thumbs/'.$IMAGE);	
			
			$this->load->model('crud_model');
			$this->crud_model->delete_partenaires($this->uri->segment(3));
			
			$data['title'] = 'Admin Partenaires';	
			$data['partenaires'] = $this->home_model->list_partenaires();
			$data['message'] = $this->admin_model->list_message();	
			$data['content'] = 'admin/admin_partenaires';
			$data['success'] = 'display:block;';
			$this->load->view('admin/template/template',$data);
			}
			else 
			{
			
			$data['error'] = 'display: block;';
			$data['title'] = 'Admin Partenaires';
			$this->load->model('admin_model');
			$data['partenaires'] = $this->home_model->list_partenaires();	
			$data['content'] = 'admin/admin_partenaires';
			$this->load->view('admin/template/template',$data);
			
			}
		}
		else {
			$this->load->view('admin/signup');
		}
	}


	function update_partenaires()
	{
		$data['error'] ='display: none;';
		$data['partenaire']  ='active';
		if($this->session->userdata('email') || $this->session->userdata('logged'))
		{
				
			$data['title'] = 'Editer Partenaires';
			$this->load->model('admin_model');
			if ($this->uri->segment(3)) 
			{
			$this->load->model('admin_model');
			$data['message'] = $this->admin_model->list_message();
			$data['rows'] = $this->admin_model->get_partenaires($this->uri->segment(3));
			// variable transmis à la vue
			$data['id'] = $data['rows']->id_partenaires;
			$data['title'] = $data['rows']->partenaires_title;
			$data['link'] = $data['rows']->partenaires_link;
			$data['photos'] = $data['rows']->partenaires_photos;
			} 
			else 
			{
				redirect('admin_partenaires');
			}
			
			
			$data['content'] = 'admin/admin_partenaires_edit';
			$this->load->view('admin/template/template',$data);	
		}
		else 
		{
			$this->load->view('admin/signup',$data);
		}
	}




	function update_upload(){
		if($this->session->userdata('email') || $this->session->userdata('logged')) 
		{
			if($this->uri->segment(3))
			{
				$this->load->model('admin_model');
				$data['message'] = $this->admin_model->list_message();
				$data['rows'] = $this->admin_model->get_partenaires($this->uri->segment(3));
				// variable transmis à la vue
				$data['id'] = $data['rows']->id_partenaires;
				$data['title'] = $data['rows']->partenaires_title;
				$data['link'] = $data['rows']->partenaires_link;
				$data['photos'] = $data['rows']->partenaires_photos;
				
				//condition upload
				$config['upload_path'] = './uploads/partenaires/';
				$config['allowed_types'] = 'gif|png|jpeg|jpg';
				$config['max_size'] = '3048';
				$config['encrypt_name'] = true;

				$this->load->library('upload',$config);

				if (!$this->upload->do_upload()) 
				{
					$this->lang->load('upload', $this->config->item('language'));
					$data['error_upload'] = $this->upload->display_errors();
					$data['title'] = 'Add Slider';
					$data['content'] = 'admin/admin_partenaires_edit';
					$this->load->view('admin/template/template',$data);
				}
				else 
				{
					$this->load->model('admin_model');
					$data['message'] = $this->admin_model->list_message();
					//-- supprimer image ancienne
					$donne['row'] = $this->admin_model->get_partenaires($this->uri->segment(3));
					echo $IMAGE = $donne['row']->partenaires_photos;
					@unlink('uploads/partenaires/'.$IMAGE);
					@unlink('uploads/partenaires/thumbs/'.$IMAGE);
					//update 
					$image_data = $this->upload->data();
					$config = array(
						'image_library' => 'GD2', 
						'source_image' => $image_data['full_path'],
						'new_image' => './uploads/partenaires/thumbs/',
						'create_thumb' => TRUE,
						'thumb_marker' => '',
						'maintain_ratio' => FALSE,
						'width'=> 466,
						'height' => 311
					);
					$this->load->library('image_lib',$config);
					$this->image_lib->resize();
					$image_name = $image_data['file_name'];
					$this->load->model('admin_model');
					$data['message'] = $this->admin_model->list_message();
					$data = array(
						'partenaires_photos' => $image_name,
						'partenaires_title' => $this->input->post('title'),
						'partenaires_link' => $this->input->post('link'),
					);
					$this->admin_model->update_partenaires($this->uri->segment(3),$data);

					$data['success'] ='display: block;';
					$this->load->model('admin_model');	
					$data['partenaires'] = $this->home_model->list_partenaires();	
					$data['message'] = $this->admin_model->list_message();
					$data['content'] = 'admin/admin_partenaires';
					$this->load->view('admin/template/template',$data);
					
				}
				
			}
			else 
			{
					$data['error'] ='display: block;';
					$this->load->model('admin_model');	
					$data['partenaires'] = $this->home_model->list_partenaires();	
					$data['message'] = $this->admin_model->list_message();
					$data['content'] = 'admin/admin_partenaires';
					$this->load->view('admin/template/template',$data);	
			}		
		}
		else 
		{
			$this->load->view('admin/signup',$data);
		}
	}
	
	
	
	
}		
?>